New public function to get the selected location from menu item callbacks
authorFederico Mena Quintero <federico@gnome.org>
Tue, 18 Dec 2012 02:05:23 +0000 (20:05 -0600)
committerFederico Mena Quintero <federico@gnome.org>
Tue, 18 Dec 2012 02:05:23 +0000 (20:05 -0600)
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
gtk/gtkplacessidebar.c
gtk/gtkplacessidebar.h

index 1133958a6aed8ab0e635a62c90181e9a8a2588cb..7ede59be14a9b4a59e3b0c463458a16ec2760dfa 100644 (file)
@@ -3806,6 +3806,44 @@ gtk_places_sidebar_set_current_location (GtkPlacesSidebar *sidebar, GFile *locat
        g_free (uri);
 }
 
+/**
+ * gtk_places_sidebar_get_selected_location:
+ * @sidebar: a places sidebar
+ *
+ * When you connect to the populate-popup signal for the @sidebar, the callback functions
+ * for your menu items will need to know the file to which the contextual menu refers.  Use
+ * this function to obtain that file's location.
+ *
+ * Returns: a GFile with the selected location, or #NULL if nothing is visually selected.
+ * It may be the case that the sidebar doesn't have anything visually selected because
+ * the location being shown in the sidebar's surrounding widgets is not actually
+ * in the list of places that the sidebar shows.  In that case, use
+ * gtk_places_sidebar_get_current_location().
+ */
+GFile *
+gtk_places_sidebar_get_selected_location (GtkPlacesSidebar *sidebar)
+{
+       GtkTreeIter iter;
+       GFile *file;
+
+       g_return_val_if_fail (sidebar != NULL, NULL);
+
+       file = NULL;
+
+       if (get_selected_iter (sidebar, &iter)) {
+               char *uri;
+
+               gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
+                                   PLACES_SIDEBAR_COLUMN_URI, &uri,
+                                   -1);
+
+               file = g_file_new_for_uri (uri);
+               g_free (uri);
+       }
+
+       return file;
+}
+
 /**
  * gtk_places_sidebar_set_show_desktop:
  * @sidebar: a places sidebar
index 15f70a4380ce7c51616ec5d60eb9f45498a34edd..8d1fef31f1a5fbe72d19d65e214418e03336ac78 100644 (file)
@@ -57,6 +57,8 @@ GtkWidget *gtk_places_sidebar_new (void);
 
 void gtk_places_sidebar_set_current_location (GtkPlacesSidebar *sidebar, GFile *location);
 
+GFile *gtk_places_sidebar_get_selected_location (GtkPlacesSidebar *sidebar);
+
 void gtk_places_sidebar_set_show_desktop (GtkPlacesSidebar *sidebar, gboolean show_desktop);
 
 void gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar, gboolean show_trash);